<template>
    <div>
        <Row :gutter="20">
            <Col span="12">
                <h3>近两日电话统计</h3>
                <Table stripe :columns="columns2" :data="list2"></Table>
            </Col>
            <Col span="12">
                 <h3>用户积分统计</h3>
            <Table stripe :columns="columns3" :data="list3"></Table>
            <Page :total="pagedata3.total" size="small" :current="pagedata3.current" :page-size="pagedata3.pageSize" :page-size-opts="pagedata3.pageSizeOpts"
                    @on-change="pageChange3" @on-page-size-change="sizeChange3"
                show-elevator show-sizer show-total></Page>
            </Col>
        </Row>
    </div>
</template>
<script>
import { getTelnoConnectNum, getuseraccount } from '@/api/other'
export default {
  name: 'invent',
  data () {
    var self = this
    return {
      showdata: false,
      columns2: [
        {
          title: '日期',
          key: 'date'
        },
        {
          title: '总数',
          key: 'count'
        }
      ],
      list2: [],
      columns3: [
        {
          title: 'NO',
          key: 'no',
          render: function (h, params) {
            const index = params.index + 1
            var div = h('div', {}, index)
            return div
          }
        },
        {
          title: '用户id',
          key: 'id'
        },
        {
          title: '用户名',
          key: 'wname'
        },
        {
          title: '金积分',
          sortable: true,
          key: 'goldscore'
        },
        {
          title: '银积分',
          sortable: true,
          key: 'siliverscore'
        },
        {
          title: '总积分',
          sortable: true,
          key: 'sumscore'
        }
      ],
      list3: [],
      pagedata3: {
        total: 0,
        current: 1,
        pageSize: 10,
        pageSizeOpts: [10, 50, 100]
      }
    }
  },
  methods: {
    getTabeData2 () {
      getTelnoConnectNum().then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
          this.list2 = []
        } else {
          this.list2 = data.data.countlist
        }
      })
    },
    getTabeData3 () {
      const page = this.pagedata3.current
      const size = this.pagedata3.pageSize
      getuseraccount({ page, size }).then(res => {
        const data = res.data
        if (data.code !== 200) {
          this.$Message.error(data.msg)
          this.list3 = []
          this.pagedata3.total = 0
          this.pagedata3.current = 1
        } else {
          this.pagedata3.total = data.data.count
          this.list3 = data.data.list
        }
      })
    },
    pageChange3 (current) {
      this.pagedata3.current = current
      this.getTabeData3()
    },
    sizeChange3 (pageSize) {
      this.pagedata3.pageSize = pageSize
      this.pagedata3.current = 1
      this.getTabeData3()
    }
  },
  mounted () {
    this.getTabeData2()
    this.getTabeData3()
  }
}
</script>
